// pages/music/music.js
const { http, handleTitle } = require('../../utils/index')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        music: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var url = `http://47.108.197.28:3000/top/playlist?cat=华语`
        http({
            url,
            success: res => {
                // console.log(res);
                this.handleHttpData(res)
            }
        })
    },
    handleItem(e) {
        var {aid} = e.currentTarget.dataset;
        wx.navigateTo({
            url: `/pages/detail/detail?id=${aid}`
        });
    },
    handleHttpData(res) {
        var playlists = res.data.playlists;
        var music = [];
        playlists.forEach(item => {
            var { id, name, coverImgUrl } = item;
            music.push({
                id,
                name: handleTitle(name),
                coverImgUrl
            })
        })
        this.setData({
            music
        })
    }

})